#include "dominion.h"
#include "dominion_helpers.h"
#include "rngs.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include <math.h>


int main () {
        int i, p, x, n, k[10] = {adventurer, council_room, feast, gardens, mine, remodel, smithy, village, baron, salvager};
        int result;
        struct gameState G;

        printf("----Random testing of smithy Card----\n");
        printf("Starting Random tests\n");
        int numOfTests = floor(Random() * 10000);

        for(n = 0; n < numOfTests; n++)
        {
           for (i = 0; i < sizeof(struct gameState); i++) {
            ((char*)&G)[i] = floor(Random() * 256);
        }
		p = floor(Random() * (MAX_PLAYERS - 2)) + 2;
              
                //Initialize the game with random players
		result = initializeGame((rand() % 3 + 2), k, rand(), &G);
                assert(result == 0);
				
                G.numPlayers = p;
                G.whoseTurn = p;
                //randomize deckcount, discard count, and handcount
                G.deckCount[p] = floor(Random() * MAX_DECK);
                G.discardCount[p] = floor(Random() * MAX_DECK);
                G.handCount[p] = (rand() % 3) + 2;
                
                printf ("play number %d \n" , n+1); 
		int CountBeforePlay =0;
                    CountBeforePlay =  G.deckCount[p] + G.discardCount[p];
		int HandCountBeforePlay =0;
	            HandCountBeforePlay=G.handCount[p];  //hand count before playing the smithy 
				 
	            result = cardEffect(smithy, 0, 0, 0, &G, 0, 0);
				
	       //     assert(result == 0);
				
	            int CountAfterPlay =0;
                        CountAfterPlay =  G.deckCount[p] + G.discardCount[p];   //total will be 3 less than the total before the play
                    int HandCountAfterPlay =0;
		        HandCountAfterPlay=G.handCount[p];  // this adds three cards and one card (played card) discarded  from hand
				
		 printf ("Befire playing Smithy card: The number of cards in deck+discard is %d  \n" , CountBeforePlay);
                 printf ("After playing Smithy card: The number of cards in deck+discard piles is 3 cards less than the before playing  %d  \n" , CountAfterPlay);
                 printf ("\n");
				 
		 printf ("Before playing Smithy card: Number of cards in hand is %d  \n" , HandCountBeforePlay);
                 printf ("After playing Smithy card: The number of cards in hand is 2 more than befor play  : %d  \n" , HandCountAfterPlay);
                 printf ("\n");
			
                //Ensure that three cards have been decremented after playing Smithy card
                 assert((CountAfterPlay + 3) == CountBeforePlay);
                //Ensure that three cards added and one card dicarded(the played card) from hand after play
                 assert(HandCountAfterPlay == (HandCountBeforePlay +2));

        }

        printf("Random tests completed\n\n");
        return 0;
}

